﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace DDOS.Game_State
{
    class TitleLayer: ScreenLayer
    {
        private int time;
        private Vector2 center;
        private Vector2 spot;
        private Vector2 spotV;
        private bool canCrunch;

        public TitleLayer()
            :base(false)
        {
            canCrunch = true;
            spotV = new Vector2(-15, -10);
            spot = new Vector2(0, 0);
            center = new Vector2((float)ScreenManager.Instance.ScreenBounds.Center.X - (ImageManager2D.Instance.Logo.Width / 2), (float)ScreenManager.Instance.ScreenBounds.Center.Y - (ImageManager2D.Instance.Logo.Height));
            time = 0;
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gt)
        {
            time += 1;
            if(time%5 == 0)
                spot = new Vector2(spot.X + spotV.X, spot.Y + spotV.Y);
            if (time > 255 && canCrunch)
            {
                SoundManager.Instance.CrunchInstance.Volume = 1.0f;
                SoundManager.Instance.CrunchInstance.Play();
                canCrunch = false;
            }
                
                
            if (spot.X > 0)
            {
                spot .X = 0;
                spotV.X *= -1;
            }
            if (spot.X < -300)
            {
                spot.X = -300;
                spotV.X *= -1;
            }
            if (spot.Y > 0)
            {
                spot.Y = 0;
                spotV.Y *= -1;
            }
            if (spot.Y < -300)
            {
                spot.Y = -300;
                spotV.Y *= -1;
            }
            if (time > 400 || InputManager.InputManagerInstance.GamePadButtonWasPressed(Buttons.Start) || InputManager.InputManagerInstance.KeyWasReleased(Keys.Enter))
            {
                ScreenManager.Instance.LoadScreen(new MainMenuScreen());
            }
        }

        

        public override void Draw()
        {
            ScreenManager.Instance.CurrentSpriteBatch.Draw(ImageManager2D.Instance.Logo, Vector2.Zero, Color.White);
            if(time <265)    
                ScreenManager.Instance.CurrentSpriteBatch.Draw(ImageManager2D.Instance.Spotlgiht, spot, Color.White);
                
            
        }
    }
}
